package com.bj58.mis.bigdata.mdp.sys.controller;

import com.bj58.bsp.v2.Provider;
import com.bj58.bsp.v2.exception.BspException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bsp/org")
public class BspOrgController {

    /**
     * 分页查询部门列表
     * @param page
     * @param limit
     * @return
     * @throws BspException
     */
    @RequestMapping("")
    public Object queryPage(@RequestParam(name="page",defaultValue = "1") Integer page,
                            @RequestParam(name="limit",defaultValue = "10") Integer limit,
                            @RequestParam(name="status",defaultValue = "1") Integer status) throws BspException {
        return Provider.getOrgService().getOrgPageList(page, limit, status);

    }

    /**
     * 根据部门 id 查询部门信息
     * @param orgId
     * @return
     * @throws BspException
     */
    @RequestMapping("/{orgId}")
    public Object get(@PathVariable("orgId") String orgId) throws BspException {
        return Provider.getOrgService().getOrgByOrgId(orgId);
    }

    /**
     * 根据父部门 id 查询一级子部门（启用的）列表
     * @param orgId
     * @return
     * @throws BspException
     */
    @RequestMapping("/{orgId}/children")
    public Object queryChildren(@PathVariable("orgId") String orgId) throws BspException {
        return Provider.getOrgService().getOrgSonListByParentId(orgId);
    }

    /**
     * 根据部门 id 查询部门的负责人列表
     * @param orgId
     * @return
     * @throws BspException
     */
    @RequestMapping("/{orgId}/managers")
    public Object queryManagers(@PathVariable("orgId") String orgId) throws BspException {
        return Provider.getOrgService().getOrgManagers(orgId);
    }

    /**
     * 根据部门 id 查询部门下人员（启用的）列表（不包含子部门的人）
     * @param orgId
     * @return
     * @throws BspException
     */
    @RequestMapping("/{orgId}/users")
    public Object queryUsers(@PathVariable("orgId") String orgId) throws BspException {
        return Provider.getOrgService().getUsersInOrg(orgId);
    }


}
